layui.define(['table', 'form', 'element'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form, element = layui.element;

  var userId = $('input[name="userId"]').val();
  var merchantUserId = $('input[name="merchantUserId"]').val();

    table.render({
        elem: '#LAY-table-func-model'
        ,url: layui.setter.webRoot + '/clerk/func_model/list.data'
        ,where:{userId:userId,merchantUserId:merchantUserId}
        ,method: 'post'
        ,parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.body.total,
                "data": res.body.data
            };
        }
        ,response: {statusCode: 200}
        ,size:'lg'
        ,cols: [[
            {field: 'funcModelId', title: 'ID'}
            ,{field: 'name', title: '功能模块名称',templet:function (record){
                return record.funcModel.name;
             }}
            ,{field: 'type', title: '功能类型',templet:function (record){
                    return record.funcModel.typeName;
                }}
            ,{field: 'iconUrl', title: 'ICON图标',templet:function (record){
                    if(record.funcModel.iconUrl) {
                        return '<img src="' + record.funcModel.iconUrl + '" style="max-height:100%;margin:auto;display:block;">';
                    }else{
                        return '<img src="'+layui.setter.webRoot + '/layuiadmin/style/res/default01.png" style="max-height:100%;margin:auto;display:block;"/>';
                    }
                }}
            ,{field: 'stateName', title: '状态'}
            ,{field: 'createDate', title: '创建时间'}
            ,{title: '操作', width: 80, align:'center', fixed: 'right',templet:function (record){
                var html = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delFuncModel">移除</a>';
                return html;
            }}
        ]]
        ,page: false
        ,height: 'full'
        ,text: '对不起，加载出现异常！'
    });

    table.render({
        elem: '#LAY-table'
        ,url: layui.setter.webRoot + '/clerk/place/list.data'
        ,where:{userId:userId,merchantUserId:merchantUserId}
        ,method: 'post'
        ,parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.body.total,
                "data": res.body.data
            };
        }
        ,response: {statusCode: 200}
        ,cols: [[
			{field: 'id', title: '网点ID'}
            ,{field: 'name', title: '网点名称'}
            ,{field: 'typeNames', title: '网点类型'}
            ,{field: 'areaName', title: '所在区域'}
			,{field: 'agentId', title: '代理姓名'	,templet:function (record){
                return record.user.name;
             }}
			 ,{field: 'agentPhone', title: '代理手机号',templet:function (record){
                 return record.user.phone;
             }}
            ,{field: 'stateName', title:'状态'}
            ,{field: 'createDate', title: '创建时间'}
        ]]
        ,page: true
        ,limit: 30
        ,height: 'full-220'
        ,text: '对不起，加载出现异常！'
    });

    element.on('tab(tab-info)', function (data) {
        if(data.index== 0){
			table.reload('LAY-table')
        }else if(data.index== 1){
            table.reload('LAY-table-func-model')
        }
    });

    //事件
    var active = {
        
    }

    $('.layui-btn.LAY-btn-fun').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    table.on('tool(LAY-table-func-model)', function(obj){
        var type = obj.event ;
        active[type] ? active[type].call(this,obj) : '';
    });
	
	table.on('tool(LAY-table)', function(obj){
        var type = obj.event ;
        active[type] ? active[type].call(this,obj) : '';
    });

  exports('clerk_info', {})
});